<?php
/*
 * tuandui
 * author wangjian
 * time 2013-04-21 
 *
 */

if (! defined('BASEPATH')) {
	exit('Access Denied');
}

class Team extends CI_Controller {
	private $username ;
	function Team(){
		parent::__construct();
		$this->load->library('admin_common');//加载admin的公用方法
		date_default_timezone_set('Asia/Shanghai');
		$this->load->model('admin/team/M_team');
		$this->load->library('session');//加载session
		$this->username =  $this->session->userdata('username');
	}
	function team_list(){
		$this->load->view('admin/master/views_team_list');
	}
	//团队职位
	function team_duty(){
		$this->load->view('admin/master/views_team_duty');
	}
	//添加职务页面
	function team_duty_add(){
		$this->load->view('admin/master/views_duty_add');
	}
	//处理添加职务页面
	function team_duty_add_do(){
		$post_data = $this->input->post(NULL,true) ;
		$duty_name =  html_escape($this->admin_common->do_addslashes(trim($post_data['duty_name'])));
		$status = (int)$post_data['status'];
		$data = array(
			'duty_name'=>$duty_name ,
			'duty_status'=>$status ,
			'duty_createtime'=>date("Y-m-d H:i:s",time()),
			'duty_updatetime'=>date("Y-m-d H:i:s",time()),
			'duty_creator'=>$this->username,
			'duty_last_person'=>$this->username,
		);
		$sql_exists = "SELECT duty_id from common_duty WHERE duty_name='{$duty_name}'" ;
		$one_res = $this->M_team->query_one($sql_exists);
		$code = 0 ;//错误
		$error_message = '' ;//错误信息
		if($one_res){
			$code = 0 ;//错误
			$error_message='你要添加的职务名称已经存在';
		}else{
			$code = $this->M_team->insert_one($data)  ;
			if(!$code){
				$error_message = '服务器繁忙请稍后' ;
			}
		}
		
		echo $res =  $this->admin_common->result_to_towf_new('',$code,$error_message,null);
	
		//echo $post_data ;
	}

	
}
